package cn.com.zal.cgweb.pojo;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * TcOrder entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see cn.com.zal.cgweb.pojo.TcOrder
 * @author MyEclipse Persistence Tools
 */

public class TcOrderDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(TcOrderDAO.class);
	// property constants
	public static final String USER_ID = "userId";
	public static final String TOTAL_AMOUNT = "totalAmount";
	public static final String CONSIGNEE = "consignee";
	public static final String RECEIVING_ADDRESS = "receivingAddress";
	public static final String STATE = "state";
	public static final String SHIPPING_USER_NAME = "shippingUserName";
	public static final String SHIPPING_ADDRESS = "shippingAddress";
	public static final String RECEIVING_PHONE = "receivingPhone";
	public static final String RECEIVING_MOBILE_PHONE = "receivingMobilePhone";
	public static final String RECEIVING_FAX = "receivingFax";
	public static final String SHIPPING_PHONE = "shippingPhone";
	public static final String SHIPPING_MOBILE_PHONE = "shippingMobilePhone";
	public static final String SHIPPING_FAX = "shippingFax";
	public static final String CHECK_REMARK = "checkRemark";
	public static final String REMARK = "remark";
	public static final String RECEIVING_COMPANY_NAME = "receivingCompanyName";
	public static final String RECEIVING_CITY = "receivingCity";
	public static final String RECEIVING_POST_NUM = "receivingPostNum";
	public static final String RECEIVING_EMAIL = "receivingEmail";
	public static final String SHIPPING_COMPANY_NAME = "shippingCompanyName";
	public static final String SHIPPING_CITY = "shippingCity";
	public static final String SHIPPING_POST_NUM = "shippingPostNum";
	public static final String SHIPPING_EMAIL = "shippingEmail";

	public void save(TcOrder transientInstance) {
		log.debug("saving TcOrder instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TcOrder persistentInstance) {
		log.debug("deleting TcOrder instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TcOrder findById(java.lang.String id) {
		log.debug("getting TcOrder instance with id: " + id);
		try {
			TcOrder instance = (TcOrder) getSession().get(
					"cn.com.zal.cgweb.pojo.TcOrder", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TcOrder instance) {
		log.debug("finding TcOrder instance by example");
		try {
			List results = getSession().createCriteria(
					"cn.com.zal.cgweb.pojo.TcOrder").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TcOrder instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TcOrder as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserId(Object userId) {
		return findByProperty(USER_ID, userId);
	}

	public List findByTotalAmount(Object totalAmount) {
		return findByProperty(TOTAL_AMOUNT, totalAmount);
	}

	public List findByConsignee(Object consignee) {
		return findByProperty(CONSIGNEE, consignee);
	}

	public List findByReceivingAddress(Object receivingAddress) {
		return findByProperty(RECEIVING_ADDRESS, receivingAddress);
	}

	public List findByState(Object state) {
		return findByProperty(STATE, state);
	}

	public List findByShippingUserName(Object shippingUserName) {
		return findByProperty(SHIPPING_USER_NAME, shippingUserName);
	}

	public List findByShippingAddress(Object shippingAddress) {
		return findByProperty(SHIPPING_ADDRESS, shippingAddress);
	}

	public List findByReceivingPhone(Object receivingPhone) {
		return findByProperty(RECEIVING_PHONE, receivingPhone);
	}

	public List findByReceivingMobilePhone(Object receivingMobilePhone) {
		return findByProperty(RECEIVING_MOBILE_PHONE, receivingMobilePhone);
	}

	public List findByReceivingFax(Object receivingFax) {
		return findByProperty(RECEIVING_FAX, receivingFax);
	}

	public List findByShippingPhone(Object shippingPhone) {
		return findByProperty(SHIPPING_PHONE, shippingPhone);
	}

	public List findByShippingMobilePhone(Object shippingMobilePhone) {
		return findByProperty(SHIPPING_MOBILE_PHONE, shippingMobilePhone);
	}

	public List findByShippingFax(Object shippingFax) {
		return findByProperty(SHIPPING_FAX, shippingFax);
	}

	public List findByCheckRemark(Object checkRemark) {
		return findByProperty(CHECK_REMARK, checkRemark);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByReceivingCompanyName(Object receivingCompanyName) {
		return findByProperty(RECEIVING_COMPANY_NAME, receivingCompanyName);
	}

	public List findByReceivingCity(Object receivingCity) {
		return findByProperty(RECEIVING_CITY, receivingCity);
	}

	public List findByReceivingPostNum(Object receivingPostNum) {
		return findByProperty(RECEIVING_POST_NUM, receivingPostNum);
	}

	public List findByReceivingEmail(Object receivingEmail) {
		return findByProperty(RECEIVING_EMAIL, receivingEmail);
	}

	public List findByShippingCompanyName(Object shippingCompanyName) {
		return findByProperty(SHIPPING_COMPANY_NAME, shippingCompanyName);
	}

	public List findByShippingCity(Object shippingCity) {
		return findByProperty(SHIPPING_CITY, shippingCity);
	}

	public List findByShippingPostNum(Object shippingPostNum) {
		return findByProperty(SHIPPING_POST_NUM, shippingPostNum);
	}

	public List findByShippingEmail(Object shippingEmail) {
		return findByProperty(SHIPPING_EMAIL, shippingEmail);
	}

	public List findAll() {
		log.debug("finding all TcOrder instances");
		try {
			String queryString = "from TcOrder";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TcOrder merge(TcOrder detachedInstance) {
		log.debug("merging TcOrder instance");
		try {
			TcOrder result = (TcOrder) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TcOrder instance) {
		log.debug("attaching dirty TcOrder instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TcOrder instance) {
		log.debug("attaching clean TcOrder instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}